<template>
  <el-cascader
    class="inputW"
    :options="treeData"
    :props="props"
    separator="-"
    :value="value"
    @change="changeValue"
  />
</template>
<script>
import { _getDepartmentList } from '@/api/department'
import { tranListToTreeData } from '@/utils/index'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      treeData: [],
      props: {
        label: 'name',
        value: 'id'
      }
    }
  },
  created() {
    this.getDepartmentList()
  },
  methods: {
    async getDepartmentList() {
      this.treeData = tranListToTreeData(await _getDepartmentList(), 0)
    },
    changeValue(array) {
      // console.log(e)
      if (array.length) {
        this.$emit('input', array[array.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }
}
</script>
